unit uSAF0201_07;

interface

uses
   Windows,
   Messages,
   SysUtils,
   Variants,
   Classes,
   Graphics,
   Controls,
   Forms,
   Dialogs,
   StdCtrls,
   Mask,
   rxToolEdit,
   ActnList,
   Buttons;

type
   TfrmEspelho = class(TForm)
      lblSelecionarContrato: TLabel;
      actlstEspelho: TActionList;
      actSelecionaContrato: TAction;
      btnEspelhar: TBitBtn;
      actEspelhar: TAction;
      btnFechar: TBitBtn;
      actFechar: TAction;
    edtSelecionarContrato: TEdit;
    btnSelecionarContrato: TBitBtn;

      procedure FormShow(Sender: TObject);
      procedure actFecharExecute(Sender: TObject);
      procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure btnEspelharClick(Sender: TObject);
    procedure btnSelecionarContratoClick(Sender: TObject);

   private

      { Private declarations }

   public

      { Public declarations }

   end;

var
   frmEspelho: TfrmEspelho;

implementation

uses
   uLibGlobal,
   uSAF0201_00,
   uSAF0201_01,
   uSAF0201_02,
   uSAF0201_03,
   uSAF0201_04;

{$R *.dfm}

procedure TfrmEspelho.actFecharExecute(Sender: TObject);
begin
   Self.Close;
end;

procedure TfrmEspelho.btnEspelharClick(Sender: TObject);
begin
//
end;

procedure TfrmEspelho.btnSelecionarContratoClick(Sender: TObject);
var
   retornoBusca: Integer;
begin
   try
      FreeAndNil(frmBuscar);
   finally
      frmBuscar := TfrmBuscar.Create(nil);
      frmBuscar._TIPO_BUSCA := frmInsUpd._BUSCA_20_CONTRATO_ESPELHO;
      frmBuscar.ShowModal;

      retornoBusca := frmBuscar._RETORNA_BUSCA;

      if (retornoBusca > 0) then
      begin
         _instrucaoSQL :=
            'SELECT'+ #13 +
            '' + #13 +
            ' (CAST((RIGHT(' + '''00''' + ' + ' + 'CAST(SAF0201.ID_REF_CONTRATO_1 AS VARCHAR), 2)) AS VARCHAR(2))' + ' + ' + '''.''' + ' + ' + #13 +
            ' CAST(SAF0201.ID_REF_CONTRATO_2 AS VARCHAR(255))' + ' + ' + '''/''' + ' + ' + #13 +
            ' CAST((RIGHT(' + '''0000''' + ' + ' + 'CAST(SAF0201.ID_REF_CONTRATO_3 AS VARCHAR), 4)) AS VARCHAR(4))) AS DSC_ID_REF_CONTRATO' + #13 +
            '' + #13 +
            'FROM SAF0201' + #13 +
            '' + #13 +
            'WHERE' + #13 +
            'ID_CONTRATO = ' + VarToStr(retornoBusca);

         edtSelecionarContrato.Text := fRetornaSQLADO(DMDados.qryAuxiliar, _instrucaoSQL);
      end;

      edtSelecionarContrato.SetFocus;
   end;
end;

procedure TfrmEspelho.FormKeyPress(Sender: TObject; var Key: Char);
begin
   fTabToEnter(Key, Self);
end;

procedure TfrmEspelho.FormShow(Sender: TObject);
begin
   fMontarTelaInsUpd(Self, 100, 320);
end;

end.

